<?php
/**
 * Created by PhpStorm.
 * User: yinnannan
 * Date: 16/1/19
 * Time: 上午5:15
 */
require('application/classes/api/userassert.php');

require('application/classes/api/recordscore.php');
class usersign  {

    public function getListByMonth($parm){
        $result = DB::select('*')->from('sysusersign')->where("signDate","<=",$parm['end'])->and_where('signDate',">=",$parm['begin'])->and_where("userId","=",$parm['userId'])->execute()->as_array();
        return $result;
    }
    public function sign($parm){
        try{
            Database::instance()->begin();
            $result = DB::select('*')->from('sysusersign')->where("signDate","=",$parm['signDate']);
            if(count($result ) == 0){
                return ;
            }
            DB::insert("sysusersign",array('signDate','userId',))
                ->values(array($parm['signDate'],$parm['userId']))
                ->execute();
            $parm['score'] = 20;
            $parm['model'] = '签到';
            $parm['userId']=$parm['userId'];
            $userassert = new userassert();
            $userassert->createScore($parm);
            $recordscore = new recordscore();
            $recordscore->sign($parm);

            Database::instance()->commit();
            echo 111;
        } catch (Exception $e) {
            echo $e->getMessage();
            Database::instance()->rollback();
        }
    }
}